// @import
import HeroCtrl, { g_oHeroCtrlMap } from "../../ctrl/HeroCtrl";
import SceneData from "../../data/SceneData";
import { g_oCmdHandlerMap } from "../ICmdHandler";

// @import
import mod_gameMsgProtocol = require("../../msg/mod_gameMsgProtocol");

/**
 * 用户退出结果处理器
 */
export default class UserQuitResultHandler {
    /**
     * 处理结果
     * 
     * @param oResult 结果
     * @returns
     */
    handle(oResult: mod_gameMsgProtocol.msg.UserQuitResult): void {
        if (null == oResult) {
            return;
        }

        if ("GameScene" != SceneData._strCurrSceneName) {
            // 如果还没有进入游戏场景,
            // 则直接退出!
            console.log("当前场景 = " + SceneData._strCurrSceneName);
            return;
        }

        let oHeroCtrl: HeroCtrl = g_oHeroCtrlMap.get(oResult.quitUserId);
        g_oHeroCtrlMap.delete(oResult.quitUserId);

        cc.find("/Canvas/Holder_HeroGroup").removeChild(oHeroCtrl.node);
    }
}

// @autoExec
(function() {
    console.log("注册 -- UserQuitResultHandler");
    g_oCmdHandlerMap.set(
        mod_gameMsgProtocol.msg.MsgCode.USER_QUIT_RESULT, 
        new UserQuitResultHandler()
    );
})();
